﻿using System;
using System.Collections;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// Class1 的摘要描述
/// </summary>
public class ReadExeclData
{
    public ReadExeclData()
	{
		//
		// TODO: 在此加入建構函式的程式碼
		//
	}
    public DataSet GetEceclData()
    {
        
          // 如果Excel中的第一列為欄名,則寫成
           string sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\temp\\book1.xls;Extended Properties=\"Excel 8.0;HDR=YES\"";
           
       // string sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\temp\\book1.xls;Extended Properties=\"Excel 8.0;HDR=NO\"";
        OleDbConnection cn = new OleDbConnection();
        cn.ConnectionString = sConnectionString;
        cn.Open();

        string sSQL = "SELECT * FROM [Sheet1$]";
        OleDbCommand cmd = cn.CreateCommand();
        cmd.CommandText = sSQL;


        OleDbDataAdapter da = new OleDbDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        cn.Close();
        return ds;


        #region return arraylist
        //ArrayList AL = new ArrayList();

        //OleDbDataReader DR = cmd.ExecuteReader();
        //while (DR.Read())
        //{
        //    AL.Add(DR[0].ToString());
           
        //    //Console.WriteLine(DR[0].ToString());
        //}

        //cn.Close();
        //return AL;
        #endregion

    }
}
